<template>
    <div class="app-container">
        <el-form :model="taskMgmtVO" ref="queryRef" :inline="true" v-show="showSearch">
            <el-form-item label="人员名称" prop="receiverName">
                <el-input v-model="taskMgmtVO.receiverName" placeholder="请输入关键字" clearable style="width: 200px"
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="流程模板编号" prop="powerId">
                <el-input v-model="taskMgmtVO.powerId" placeholder="请输入关键字" clearable style="width: 200px"
                    @keyup.enter="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>  
 
        <el-table v-loading="loading" :data="entrustList">
            <el-table-column label="模板类型" align="center" prop="powerId" />

            <el-table-column label="审批人姓名" align="center" prop="name" />
            <el-table-column label="委托人姓名" align="center" prop="receiverName" />

            <el-table-column label="委托开始" align="center" prop="beginTime">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.beginTime, "{y}-{m}-{d}") }}</span>
                </template>
            </el-table-column>
            <el-table-column label="委托结束" align="center" prop="endTime">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
                </template>
            </el-table-column>
            <!-- <el-table-column label="状态" align="center" prop="effectiveStatus">
             <template #default="item">
                <el-tag>{{ item.row.effectiveStatus == 1 ? '活跃' : '不活跃' }}</el-tag> 
             </template>
          </el-table-column> -->
            <el-table-column label="创建时间" align="center" prop="createTime">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
                </template>
            </el-table-column> 
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="pageDto.page" v-model:limit="pageDto.pageSize"
            @pagination="getList" />
    </div>
</template>

<script setup>
import { ref, onMounted} from "vue";
import { getUserEntrustListPage, getFromCodeData } from "@/api/mockflow";
import { approveList } from '@/utils/flow/const'
const { proxy } = getCurrentInstance();
const entrustList = ref([]);
const loading = ref(false); 
const showSearch = ref(true);
const total = ref(0);
let formCodeOptions = ref([]);
let userOptions = ref([]); 
const data = reactive({ 
    pageDto: {
        page: 1,
        pageSize: 10
    },
    taskMgmtVO: {} 
});
const { pageDto, taskMgmtVO} = toRefs(data);

 
onMounted(async () => {
    await initFromCode();
    getList();
    getUserList();
})
const initFromCode = async () => {
    await getFromCodeData().then((res) => {
        if (res.code == 200) {
            formCodeOptions.value = res.data;
        }
    });
}
const getUserList = () => {
    const keys = Object.keys(approveList);
    for (let t of keys) {
        userOptions.value.push({
            label: approveList[t],
            value: t
        });
    }
}

/** 查询岗位列表 */
function getList() {
    loading.value = true;
    getUserEntrustListPage(pageDto.value, taskMgmtVO.value).then(response => {
        entrustList.value = response.data;
        total.value = response.pagination.totalCount;
        loading.value = false;
    });
}
 
/** 搜索按钮操作 */
function handleQuery() {
    pageDto.value.page = 1;
    getList();
}
 
/** 重置按钮操作 */
function resetQuery() {
    taskMgmtVO.value = {};
    proxy.resetForm("queryRef");
    handleQuery();
}
 
</script>